#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

class Solution {
public:
    int longestOnes(vector<int>& nums, int k)
    {
        int n = nums.size();
        int right = 0;
        int zero = 0;
        int len = 0;
      
        for (int left = 0; left < n;)
        {
            while (right < n)
            {
                if (nums[right] == 0)
                {
                    zero++;
                }
                right++;
                while (zero > k)
                {
                    if (nums[left] == 0)
                    {
                        zero--;
                    }


                    left++;
                }
                int size = right - left;
                len = max(len, size);

                }
       
            break;



        }
        return len;
    }
};

int main()
{
    int arry1[] = { 0,0,1,1,0,0,1,1,1,0,1,1,0,0,0,1,1,1,1 };
    vector<int> s;
    for (auto e : arry1)
    {
        s.push_back(e);
    }
    Solution y;
 
    cout << y.longestOnes(s, 3) << endl;


    return 0;
}